package com.xrit.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xrit.constant.MessageConstant;
import com.xrit.pojo.SetMeal;
import com.xrit.result.Result;
import com.xrit.service.SetMealService;
import com.xrit.utils.QiNiuUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setMealMobile")
public class SetMealMobileController {

    @Reference
    private SetMealService setMealService;

    /**
     * 套餐明细
     * @return
     */
    @RequestMapping("/findById")
    public Result findById(Integer id){
        SetMeal meal = setMealService.findDetailsById(id);
        meal.setImg(QiNiuUtils.DOMAIN+meal.getImg());
        return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,meal);
    }

    /**
     * 简单的套餐明细,不带检查组检查项信息
     * @param id
     * @return
     */
    @RequestMapping("/findById2")
    public Result findById2(Integer id){
        SetMeal meal = setMealService.findById(id);
        meal.setImg(QiNiuUtils.DOMAIN+meal.getImg());
        return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,meal);
    }

    @RequestMapping("getSetmeal")
    public Result getSetmeal(){
        List<SetMeal> setMeals = setMealService.findAll();
        //拼接图片
        setMeals.forEach(s->{
            s.setImg(QiNiuUtils.DOMAIN+s.getImg());
        });
        return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,setMeals);
    }

}
